import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop/pages/cart_page.dart';
import 'package:flutter_shop/pages/category_page.dart';
import 'package:flutter_shop/pages/home_page.dart';
import 'package:flutter_shop/pages/member_page.dart';
import 'package:flutter_shop/provide/currentIndex.dart';
import 'package:provide/provide.dart';

class IndexPage extends StatefulWidget{
  @override
  _indexPageState createState()=>_indexPageState();
}

class _indexPageState extends State<IndexPage>{

  Color _bottonNavationColor = Colors.blue;//设置点击的图标和字体颜色
  Color _noNavationColor=Colors.grey;//设置未选中的图标和字体颜色


  List<Widget> widgetList=new List();//存放page集合

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    widgetList
    ..add(HomePage())
    ..add(CategoryPage())
    ..add(CartPage())
    ..add(MemberPage());

  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    ScreenUtil.instance=ScreenUtil(width: 750,height: 1334)..init(context);
    return Provide<CurrentIndex>(
      builder: (context,child,current){
        return Scaffold(
          body: IndexedStack(/*页面保持状态必须为IndexedStack*/
            index: current.index,
            children:widgetList,
          ),
          bottomNavigationBar: BottomNavigationBar(items: [
            BottomNavigationBarItem(icon: Icon(CupertinoIcons.home),title: Text('首页')),
            BottomNavigationBarItem(icon: Icon(CupertinoIcons.search,),title: Text('分类')),
            BottomNavigationBarItem(icon: Icon(CupertinoIcons.shopping_cart),title: Text('购物车')),
            BottomNavigationBarItem(icon: Icon(CupertinoIcons.profile_circled,),title: Text('会员中心')),
          ],onTap: (int index){
            setState(() {
              Provide.value<CurrentIndex>(context).currentIndex(index);
            });
          },type: BottomNavigationBarType.fixed,currentIndex: current.index,),
        );
      },
    );
  }

}